
const baseUrl = 'http://localhost:8000/'
const token = wx.getStorageSync('token')
export const $request=(params={})=>{
  return new Promise((resolve,rejects)=>{
    wx.showLoading({
      title: '加载中....',
    })
    wx.request({
      url: baseUrl+params.url,
      method:params.method||"GET",
      data:params.data || {},
      header:params.header || {
        'Content-Type': 'application/json',
        // 'Authorization': `Bearer ${token}`
      },
      success:(res)=>{
        if(res.statusCode===200){
          resolve(res);
        }else{
          rejects(res)
        }
      },
      fail:(err)=>{
        rejects(err);
      },
      complete:()=>{
        wx.hideLoading()
      }
    })
  })
}